package com.hula.onion.book.server.spider.platforms.yigangjinrong;

import com.hula.onion.book.server.common.CommonResponse;
import com.hula.onion.book.server.common.SpiderCommon;
import com.hula.onion.book.server.config.ResponseStatusEnum;
import com.hula.onion.book.server.utils.HttpUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by work on 2018/1/27.
 */
@Component("yiGangJRSpider")
public class YiGangJRSpider extends SpiderCommon {
    @Autowired
    private YiGangJRSpiderHelper spiderHelper;

    private static final String LOGIN_URL="https://www.ycd360.com/user/doLogin.html";

    private static final String ACCOUNT_INFO="https://www.ycd360.com/member/index.html";
    @Override
    public CommonResponse execute() {
        String loginStr= HttpUtils.post(LOGIN_URL,
                spiderHelper.installRequestParams(loginForm),getHttpContext());
        if(StringUtils.isEmpty(loginStr)){
            return new CommonResponse(ResponseStatusEnum.FAIL);
        }
        String accountStr=HttpUtils.get(ACCOUNT_INFO,getHttpContext());
        if(StringUtils.isEmpty(accountStr)){
            return new CommonResponse(ResponseStatusEnum.QUERY_FAIL);
        }
        return spiderHelper.parseAccountBalance(accountStr);
    }
}
